`include "../include/common.sv"
module GHT #(
	parameter BUFFER_SIZE=7
)(
	input logic cpu_clk,
	input logic cpu_rst_n,
	input logic we,
	input logic real_branch,
	input logic [BUFFER_SIZE-1: 0] windex,
	input logic [BUFFER_SIZE-1: 0] rindex,
	output logic predict
);
	logic [2: 0] dina, douta, doutb, doutap1, doutat1;
	SDPRAM #(
		.WORD_WIDTH(3),
		// .INIT_FILE("init_bht.mem"),
		.DEPTH(`LSHIFTX(BUFFER_SIZE)),
		.ADDR_WIDTH(BUFFER_SIZE)
	) ght(
		.clk(cpu_clk),
		.ena(1'b1),
		.addra(windex),
		.wea(we),
		.dina(dina),
		.douta(douta),
		.enb(1'b1),
		.addrb(rindex),
		.doutb(doutb)
	);
	assign doutap1 = douta != 3'b111 ? douta + 1 : douta;
	assign doutat1 = douta > 2 ? douta - 2 : 0;
	assign dina = real_branch ? doutap1 : doutat1;
	assign predict = doutb[2];
endmodule